package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper extends BaseMapper<Emp> {
//    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
//    Long getTotal();
//    @Select("select emp.* , dept.name as deptName from emp left join dept on emp.dept_id = dept.id limit #{index} , #{pageSize}")
//    List<Emp> selectEmp(@Param("index") int index, @Param("pageSize") Integer pageSize);


    // @Select("select emp.* , dept.name as deptName from emp left join dept on emp.dept_id = dept.id")
    List<Emp> selectAll(@Param("name") String name, @Param("gender") Integer gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    List<Emp> selectAll(EmpQueryParam empQueryParam);


    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,password , name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time)" +
            " values (#{username},#{password} ,#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void saveEmp(Emp emp);


    void deleteByIds(@Param("ids") List<Integer> ids);


    Emp getEmpWithEmpExprById(Integer id);

    @Select("select * from emp where id = #{id}")
    Emp getById(Integer id);

    @Override
    int updateById(Emp emp);

    //员工职位人数统计
    @MapKey("job")
    List<Map> getEmpJobData();
    //员工性别人数统计
    @MapKey("name")
    List<Map> getEmpGenderData();

    @Select("select * from emp")
    List<Emp> selectAllEmp();
    @Select("select COUNT(*) from emp where dept_id = #{id}")
    Integer countByDeptId(Integer id);
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp  selectByUsernameAndPassword(@Param("username") String username, @Param("password") String password);
}
